/****************************************Copyright (c)**************************************************
**                                         2016-03
**
**                                
**
**
**--------------File Info-------------------------------------------------------------------------------
** File name:		    ht6x1x_flash.h
** Last modified Date:  2016-03-29
** Last Version:		v1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Created by:			Evan Chen
** Created date:		2016-03-29
** Version:				v1.0
** Descriptions:		
**
**------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
** Version:
** Descriptions:
**
********************************************************************************************************/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __HT6X1X_FLASH_H
#define __HT6X1X_FLASH_H

#ifdef __cplusplus
 extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "ht60xx.h"

#define FLASH_END_ADDRESS   ((uint32_t)0x1FFFF)
#define FLASH_SIZE 0x20000
#define FLASH_PAGE_SIZE 1024

#define M8(addr) 	(*((uint8_t *) (addr)))
#define M16(addr) 	(*((uint16_t *) (addr)))
#define M32(addr) 	(*((uint32_t *) (addr)))

typedef enum
{ 
  FLASH_COMPLETE = 0,
  FLASH_BUSY,
  FLASH_ERROR,  
  FLASH_TIMEOUT
}FLASH_Status;

/*FLASHCON*/
#define FLASHCON_BUSY_MASK   ((uint16_t)0x0004)
#define FLASHCON_BUSY_IDLE    ((uint16_t)0x0000)
#define FLASHCON_BUSY_BUSY   ((uint16_t)0x0004)

#define FLASHCON_FOP_MASK                    ((uint16_t)0x0003)
#define FLASHCON_FOP_READ_ONLY        ((uint16_t)0x0000)
#define FLASHCON_FOP_WRITE                  ((uint16_t)0x0001)
#define FLASHCON_FOP_ERASE_PAGE      ((uint16_t)0x0002)
#define FLASHCON_FOP_ERASE_ALL         ((uint16_t)0x0003)

void WPREG_Disable(void);
void WPREG_Enable(void);
FunctionalState WPREG_State(void);
void FLASH_Unlock(void);
void FLASH_Lock(void);
void FLASH_INFO_Unlock(void);
void FLASH_INFO_Lock(void);
FunctionalState FLASH_State(void);
FLASH_Status FLASH_ErasePage(uint32_t FLASH_Page);
FLASH_Status FLASH_EraseAllPage(void);
FLASH_Status FLASH_Program_M32(uint32_t Address, uint32_t Data);
FLASH_Status FLASH_Program_M16(uint32_t Address, uint16_t Data);
FLASH_Status FLASH_Program_M8(uint32_t Address, uint8_t Data);

#ifdef __cplusplus
}
#endif

#endif /* __HT6X1X_FLASH_H */

